import { http } from "@/utils/http";
import { adminUrlApi } from "@/utils/http/utils";
import type { Result, ResultTable } from "@/utils/http/utils";

/** 工具-定时任务列表 */
export const getCrontabList = (data?: object) => {
  return http.request<ResultTable>(
    "get",
    adminUrlApi("cron/getPageList"),
    { data }
  );
};

export const addCrontab = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("cron/create"), {
    data
  });
};

export const editCrontab = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("cron/update"), {
    data
  });
};

export const delCrontab = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("cron/delete"), {
    data
  });
};

export const updateStatusCrontab = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("cron/updateStatus"), {
    data
  });
};

export const resetCrontab = (data?: object) => {
  return http.request<Result>(
    "post",
    adminUrlApi("cron/reset"),
    {
      data
    }
  );
};

export const runCrontab = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("cron/run"), {
    data
  });
};

//定时任务日志列表
export const getCrontabLogList = (data?: object) => {
  return http.request<ResultTable>(
    "get",
    adminUrlApi("cron/getLogPageList"),
    { data }
  );
};

export const delCrontabLog = (data?: object) => {
  return http.request<Result>(
    "post",
    adminUrlApi("cron/logDelete"),
    {
      data
    }
  );
};

/** 工具-定时任务列表 */
export const getCodeList = (data?: object) => {
  return http.request<ResultTable>(
    "get",
    adminUrlApi("admin/toolsCode/index"),
    { data }
  );
};

export const getCodeColumns = (data?: object) => {
  return http.request<Result>("get", adminUrlApi("admin/toolsCode/columns"), {
    data
  });
};

export const getModuleName = (data?: object) => {
  return http.request<Result>(
    "get",
    adminUrlApi("admin/toolsCode/moduleName"),
    {
      data
    }
  );
};

export const addCode = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("admin/toolsCode/add"), {
    data
  });
};

export const editCode = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("admin/toolsCode/edit"), {
    data
  });
};

export const loadTable = (data?: object) => {
  return http.request<Result>(
    "post",
    adminUrlApi("admin/toolsCode/loadTable"),
    {
      data
    }
  );
};

export const delCode = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("admin/toolsCode/del"), {
    data
  });
};

export const syncCode = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("admin/toolsCode/sync"), {
    data
  });
};

export const previewCode = (data?: object) => {
  return http.request<Result>("get", adminUrlApi("admin/toolsCode/preview"), {
    data
  });
};
